<template>
	<view class="background">
		<view :style="'height:' + statusBarHeight + 'px;'"></view>
		<u-notify ref="uNotify" message="Hi uView"></u-notify>
		<view class="position_t flex aic jcsb">

			<image @click="back()" src="@/static/back.png" mode=""></image>
			<view class="position_t_right">
				<!-- <text class="fonts14" @click="reportApply()" v-if="bId">应聘报名表</text> -->
				<text class="fonts14" @click="report()" v-if="indexValue == 3">报告详情</text>
				<image v-if="personData.isCollection == 0" src="@/static/sc.png" mode="" @click="collectionApi()"></image>
				<image v-if="personData.isCollection == 1" src="@/static/collects.png" mode="" @click="collectionApi()">
				</image>
			</view>
		</view>
		<view class="content_">
			<view class="position_content">
				<Inventory2 :data="personData" />
			</view>
			<view class="position_content_main">
				<p class="fontz fontc3d fontw700 fonts12" style="margin-bottom: 10px;">职位描述</p>
				<p class="fontz fonts12 color2" style="white-space: pre-wrap;" v-html="personData.positionDesc">
				</p>
			</view>
			<view class="" style="margin-top: 8px;" @click="compony()">
				<ComponyRouter :data="personData.tenantVo" />
			</view>
			<view class="zhiwei_main" v-if="personData.isShowLogs == 1">
				<p class="">
					<span class="zhiwei_title fonts fonts24 fontw700">应聘进度</span>
				</p>
				<ul class="detail_aside_main_ul" v-if="logData.length != 0">
					<li class="detail_aside_main_li" v-for="(item, index) in logData" :key="index">
						<view class="detail_aside_main_li_t" v-if="item.logSpec == 1"></view>
						<view class=" aie" v-if="item.logSpec == 1">
							<p class="detail_aside_main_li_title fonts16 fontw500">{{ item.logName }} </p>
							<span class=" fonts12 gray magint10">操作时间：{{ item.createTime }}</span>
						</view>
						<view class="aie" v-if="item.status > 0 && item.logSpec == 2">
							<p class="blue fonts14  ">{{ item.logName }}</p>
							<span class=" fonts12 gray magint10">操作时间：{{ item.createTime }}</span>
						</view>
						<view class=" aie" v-if="item.status < 0 && item.logSpec == 2">
							<p class="red fonts14 magint10">{{ item.logName }}</p>
							<span class=" fonts12 gray magint10">{{ item.createTime }}</span>
						</view>
						<view class="aie" v-if="item.logSpec == 3">
							<p class="fonts14 gray magint10 " v-if="item.content">反馈内容：{{ item.content }}
							</p>
							<span class=" fonts12 gray magint10">反馈时间：{{ item.createTime }}</span>
						</view>
						<view class="flex aie" v-if="item.logSpec != 3">
							<p class="fonts14 gray magint10 " style="white-space: pre-wrap;" v-if="item.content">
								{{ item.content }}
							</p>
						</view>
					</li>
				</ul>
				<u-empty style="width: 100%;height: 500px;margin: auto;" v-if="logData.length == 0" mode="data">
				</u-empty>
			</view>
		</view>
		<view class="position_footer flex aic jcsb" v-if="indexValue != '-1'">
			<u-button class="blue_btn" style="width: 100%;" type="primary" v-if="indexValue == 0" @click="deliver()">
				投递简历
			</u-button>
			<u-button class="blue_btn" style="width: 100%;" type="primary" v-if="indexValue == 1">已投递
			</u-button>
			<u-button type="danger" style="width: 100%;" v-if="indexValue == 4">已放弃笔试</u-button>
			<u-button class="blue_btn" style="width: 100%;" type="primary" v-if="indexValue == 5">已确认参加笔试
			</u-button>
			<u-button type="danger" style="width: 48%;" v-if="indexValue == 2" @click="getup()">放弃笔试</u-button>
			<u-button class="blue_btn" style="width: 48%;" type="primary" v-if="indexValue == 2" @click="request()">
				确认参加
			</u-button>
			<!-- <el-button class="blue_btn" style="width: 100%;" type="primary" v-if="indexValue==3">上传体检报告</el-button> -->
			<view class="" style="width: 160px;" v-if="indexValue == 3">
				<UploadFileT style="width: 100%;" @uploadImageClick="uploadImageClicks_"  />
			</view>
			<view class="" style="width: 160px;" v-if="indexValue == 3">
				<UploadFileF style="width: 100%;" @uploadImageClick="uploadImageClicks_F"  />
			</view>
		</view>

	</view>
</template>

<script>
import {
	getposition,
	registration,
	collection,
	editRegistration,
	registrationLog,
} from "@/api/index"
import UploadFileT from "@/pages/components/UploadFileT.vue"
import UploadFileF from "@/pages/components/UploadFileF.vue"
import Inventory2 from "../../components/Invebtory_detail.vue";
import ComponyRouter from "../../components/ComponyRouter.vue";
import {
	dictFuns
} from "@/util/dictionary"
export default {
	components: {
		UploadFileF,
		Inventory2,
		ComponyRouter,
		UploadFileT
	},
	data() {
		return {
			logData: [],
			id: "",
			loading: false,
			personData: {
				positionRegistration: {
					medicalReportIds: ""
				}
			},
			indexValue: "-1",
			bId: "",
			statusBarHeight: uni.getSystemInfoSync().statusBarHeight,
		};
	},
	onLoad(options) {
		let params = JSON.parse(options.data)
		console.log(params);
		this.id = params.id
		// this.getpositionApi(this.id)
	},
	onShow(){
		this.getpositionApi(this.id)
	},
	methods: {
		registrationLogApi() {
			registrationLog({
				positionRegistrationId: this.personData.positionRegistration.id
			}).then(res => {
				console.log("投递日志", res);
				this.logData = res.data
			})
		},
		compony() {
			uni.navigateTo({
				url: "/pages/index/compony/compony?data=" + JSON.stringify(this.personData)
			})
		},
		back() {
			uni.navigateBack(-1)
		},
		reportApply() {
			uni.navigateTo({
				url: "/pages/index/position/applyForm/applyForm?data=" + JSON.stringify(this.personData) +
					'&indexValue=' + this.indexValue
			})
		},
		report() {
			uni.navigateTo({
				url: "/pages/index/position/report/report?data=" + JSON.stringify(this.personData)
			})
		},
		uploadImageClicks_(value) {
			console.log(value);
			let obj = {
				medicalReportIds: this.personData.positionRegistration.medicalReportIds,
				id: this.personData.positionRegistration.id
			}
			obj.medicalReportIds = obj.medicalReportIds ? obj.medicalReportIds + "," + value : value
			console.log(obj);
			this.editRegistrationApi(obj)
		},
		uploadImageClicks_F(value) {
			console.log(value);
			let obj = {
				noCriminalRecordIds: this.personData.positionRegistration.noCriminalRecordIds,
				id: this.personData.positionRegistration.id
			}
			obj.noCriminalRecordIds = obj.noCriminalRecordIds ? obj.noCriminalRecordIds + "," + value : value
			console.log(obj);
			this.editRegistrationApi(obj)
		},
		editRegistrationApi(params) {
			editRegistration(params).then(res => {
				this.getpositionApi(this.id)
				this.$refs.uNotify.show({
					top: 1,
					type: 'success',
					color: '#ffffff',
					bgColor: '#5ac725',
					message: res.msg,
					duration: 1000 * 2,
					fontSize: 20,
					safeAreaInsetTop: false
				})
			}).catch(res => {
				this.$refs.uNotify.show({
					top: 1,
					type: 'error',
					color: 'red',
					bgColor: '#f56c6c',
					message: res.msg,
					duration: 1000 * 2,
					fontSize: 20,
					safeAreaInsetTop: false
				})
			})
		},
		// 获取
		async getpositionApi(params) {
			this.loading = true
			await getposition(params).then((res) => {
				this.loading = false
				console.log("个人信息：", res);
				this.personData = res.data
				this.bId = this.personData.registrationFormTemplateId
				if (this.personData.positionRegistration == null) {
					this.indexValue = 0 //投递简历
				} else {
					if (this.personData.positionRegistration.status == 3) {
						if (this.personData.positionRegistration.writingTestingStatus == 0) {
							this.indexValue = 1 //已投递简历
						} else if (this.personData.positionRegistration.writingTestingStatus == 1) {
							this.indexValue = 2 //放弃笔试
						} else if (this.personData.positionRegistration.writingTestingStatus == "-1") {
							this.indexValue = 4 //已放弃笔试
						} else if (this.personData.positionRegistration.writingTestingStatus == 2) {
							this.indexValue = 5 //已确定笔试
						}
					}
					if (this.personData.positionRegistration.status == 5) {
						this.indexValue = 3 //上传体检报告
					}
					// if(true){
					// 	this.indexValue = 3 //
					// }
				}
				this.registrationLogApi()

			})
		},
		getup() {
			let params = {
				id: this.personData.positionRegistration.id,
				writingTestingStatus: "-1"
			}
			this.editRegistrationApi(params)
		},
		request() {
			let params = {
				id: this.personData.positionRegistration.id,
				writingTestingStatus: 2
			}
			this.editRegistrationApi(params)
		},
		deliver() { //投递简历
			registration({
				positionId: this.id
			}).then(res => {
				this.$refs.uNotify.show({
					top: 1,
					type: 'success',
					color: '#ffffff',
					bgColor: '#5ac725',
					message: res.msg,
					duration: 1000 * 2,
					fontSize: 20,
					safeAreaInsetTop: false
				})
				this.getpositionApi(this.id)
			}).catch(res => {
				// this.$refs.uNotify.show({
				// 	top: 1,
				// 	type: 'error',
				// 	color: 'red',
				// 	bgColor: '#f56c6c',
				// 	message: res.msg,
				// 	duration: 1000 * 2,
				// 	fontSize: 20,
				// 	safeAreaInsetTop: false
				// })
			})
		},
		collectionApi() { //收藏职位
			collection({
				positionId: this.id
			}).then(res => {
				this.$refs.uNotify.show({
					top: 1,
					type: 'success',
					color: '#ffffff',
					bgColor: '#5ac725',
					message: res.msg,
					duration: 1000 * 2,
					fontSize: 20,
					safeAreaInsetTop: false
				})
				this.getpositionApi(this.id)
			}).catch(res => {
				this.$refs.uNotify.show({
					top: 1,
					type: 'error',
					color: 'red',
					bgColor: '#f56c6c',
					message: res.msg,
					duration: 1000 * 2,
					fontSize: 20,
					safeAreaInsetTop: false
				})
			})
		}
	}
}
</script>

<style lang="scss" scoped>
.position_t {
	// width: calc(100% - 24px);
	width: 100%;
	position: fixed;
	height: 44px;
	background-color: #fff;
	z-index: 1;

	image {
		width: 30px;
		height: 30px;
	}

	.position_t_right {
		margin-right: 120px;

		text {
			margin-right: 20px;
			color: #2F6CBC;
		}

		image {
			width: 18px;
			height: 17px;
		}
	}

}

.color2 {
	color: #606266;
}

.position_content {
	padding-top: 44px;
}

.position_content_main {
	margin-top: 10px;
	padding: 13px 15px;
	background: #FFFFFF;
}

.position_footer {
	height: 40px;
	z-index: 1;
	position: absolute;
	bottom: 10px;
	background: #ffffff;
	box-shadow: 0px -1px 3px 0px rgba(48, 48, 48, 0.0592);
	border-radius: 0px 0px 0px 0px;
	opacity: 1;
	width: calc(100% - 24px);
	padding: 12px;

	.blue_btn {
		background: #2F6CBC;
		border: 1px solid #2F6CBC;
	}
}

.zhiwei_main {
	padding: 25px;

	background: #FFFFFF;
	border-radius: 0px 0px 0px 0px;
	opacity: 1;
	margin-top: 16px;
	margin-bottom: 100px;
}

.zhiwei_main_button {
	.el-button {
		height: 40px;
	}
}

.zhiwei_title {
	position: relative;

	&::after {
		position: absolute;
		left: -25px;
		top: 10px;
		content: "";
		width: 4px;
		height: 16px;
		background: #2F6CBC;
		border-radius: 0px 2px 2px 0px;
		opacity: 1;
	}
}

.red {
	color: #B60000;
}

.gray {
	color: #898989;
}

.detail_aside_main_ul {
	padding-left: 24px;
	list-style: none;

	.detail_aside_main_li {
		// margin-bottom: 26px;
		padding: 14px 12px;
		// background: #F4F4F4;
		border-radius: 0px 0px 0px 0px;
		opacity: 1;
		position: relative;

		.detail_aside_main_li_t {
			left: -32px;
			position: absolute;
			content: "";
			top: 15px;
			width: 16px;
			height: 16px;
			opacity: 1;
			border: 1px solid #2F6CBC;
			border-radius: 50%;

			&::after {
				content: "";
				top: 4px;
				left: 4px;
				position: absolute;
				width: 8px;
				height: 8px;
				background: #2F6CBC;
				opacity: 1;
				border-radius: 50%;

			}
		}


		&:last-child {

			// margin-left: 24px;
			&::before {
				display: none;
			}
		}

		&::before {
			position: absolute;
			content: "";
			top: 7.5px;
			height: calc(100% + 22px);
			left: -24px;
			top: 32px;
			opacity: 1;
			border: 1px dashed #EAE8F2;

		}

		.detail_aside_main_li_title {}
	}
}
</style>
